package com.weitu.risk.service.impl;

import com.weitu.risk.entity.Recognise;
import com.weitu.risk.mapper.RecogniseMapper;
import com.weitu.risk.service.RecogniseService;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class RecogniseServiceImpl implements RecogniseService {
    @Autowired
    private RecogniseMapper recogniseMapper;

    @Override
    public List<Recognise> queryListByParam(Map<String, Object> map) {
        return this.recogniseMapper.queryListByParam(map);
    }

    @Override
    public int queryListCountByParam(Map<String, Object> map) {
        return this.recogniseMapper.queryListCountByParam(map);
    }

    @Override
    public Recognise queryRecogniseById(@Param("id") String id) {
        return this.recogniseMapper.queryRecogniseById(id);
    }

    @Override
    public boolean addRecognise(Map<String, Object> map) {
        int result = this.recogniseMapper.insertRecognise(map);
        if(result<1){
            return false;
        }
        return true;
    }

    @Override
    public boolean editRecognise(Map<String, Object> map) {
        int result =this.recogniseMapper.updateRecognise(map);
        if(result<1){
            return false;
        }
        return true;
    }

    @Override
    public boolean deleteRecogniseById(@Param("id") String id) {
        int result = this.recogniseMapper.deleteRecogniseById(id);
        if(result<1){
            return false;
        }
        return true;
    }
    /**
     * 添加风险评估人员信息
     * @param map
     * @return
     */
    public boolean addRecogniseUserIds(Map<String,Object> map){
        //map中存放recogniseId 和 list(用户id的集合)
        int result = this.recogniseMapper.insertRecogniseUserIds(map);
        if(result<0){
            return false;
        }
        return true;
    }

    /**
     * 编辑风险评估人员信息
     * @param map
     * @return
     */
    @Transactional
    public boolean editRecogniseUser(Map<String,Object> map){
        //map中存放recogniseId 和 list(用户id的集合)
        String recogniseId = map.get("recogniseId").toString();
        //删除
        int delResult = this.recogniseMapper.deleteRecogniseUsersByRecogniseId(recogniseId);
        //新增
        int addResult = this.recogniseMapper.insertRecogniseUserIds(map);
        if(delResult>=0&&addResult>=0){
            return true;
        }
        return false;
    }

    @Override
    public boolean editRecogniseAppState(@Param("id") String id, @Param("appState") String appState) {
        int result = this.recogniseMapper.updateRecogniseAppState(id,appState);
        if(result<1){
            return false;
        }
        return true;
    }
}